package com.cxf.windex.rest.admin;

import com.cxf.windex.base.msg.ObjectRestResponse;
import com.cxf.windex.base.msg.TableResultResponse;
import com.cxf.windex.base.rest.BaseRestController;
import com.cxf.windex.biz.JsTypeBiz;
import com.cxf.windex.entity.JsType;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @program: business_needs
 * @description: 类型
 * @author: chenxf
 * @create: 2018-10-09 17:40
 **/
@Api(tags = {"村广通[后台] - 店铺类型接口"})
@Controller
@RequestMapping("admin/type")
public class AdminTypeController extends BaseRestController<JsTypeBiz,JsType> {
    @ApiOperation(value = "查询类型", notes = "查询类型")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit", value = "记录数 默认10", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "offset", value = "页码 默认 1", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "orderStr", value = "排序 默认desc", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "code", value = "类型Code 默认shop_type", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "name", value = "类型名称", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public TableResultResponse<JsType> list(
            @RequestParam(defaultValue = "10") int limit, @RequestParam(defaultValue = "1") int offset,
            @RequestParam(defaultValue = "desc") String orderStr, @RequestParam(defaultValue = "shop_type") String code, String name) {
        List<JsType> items = baseBiz.list(limit, offset, orderStr, code, name);
        PageInfo<JsType> pageInfo = new PageInfo<JsType>(items);
        return new TableResultResponse<JsType>(Integer.parseInt(String.valueOf(pageInfo.getTotal())),
                offset, limit,
                items);
    }

    @ApiOperation(value = "保存类型", notes = "保存类型")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public ObjectRestResponse save(JsType entity){
        baseBiz.saveJsType(entity);
        return new ObjectRestResponse("保存成功").rel(true);
    }


}
